package com.xiaoyu.lanling.event.coin

import `in`.srain.cube.request.JsonData
import `in`.srain.cube.util.StringUtil
import android.text.TextUtils
import com.xiaoyu.base.event.BaseJsonEvent
import com.xiaoyu.base.utils.JsonUtil
import com.xiaoyu.lanling.feature.coin.model.CoinProductItem

class CoinChargeEvent(requestTag: Any, jsonData: JsonData) : BaseJsonEvent(requestTag, jsonData) {

    val activity = ChargeActivity(jsonData.optJson("activity"))
    val coinBalance = jsonData.optString("coinBalance")
    val productList = JsonUtil.convertToList(jsonData.optJson("productList")) { itemData -> CoinProductItem(itemData) }

    class ChargeActivity(jsonData: JsonData) {
        val icon = jsonData.optString("icon")
        val url = jsonData.optString("url")

        fun isValid(): Boolean {
            return !StringUtil.isAnyEmpty(icon, url)
        }
    }
}